using JT808Protocol.Common;
using System;
using System.Text.Json.Serialization;

namespace JT808Protocol.Models.BodyParserStrategy.Location.LocationAddition
{
    /// <summary>
    /// 线路行驶时间不足/过长报警附加信息消息体数据格式
    /// </summary>
    public class LaDriverTimeAlarm_0x13 : ILocationAddition
    {
        /// <summary>
        /// 路段ID
        /// </summary>
        [JsonPropertyName("路段ID")] public uint LineSectionID { get; set; }

        /// <summary>
        /// 路段行驶时间
        /// </summary>
        [JsonPropertyName("路段行驶时间")] public ushort LineSectionDriveTime { get; set; }

        /// <summary>
        /// 结果
        /// </summary>
        [JsonPropertyName("结果")] public byte Result { get; set; }

        public override ILocationAddition ReadEntity(ReadOnlySpan<byte> source, int startIndex)
        {
            DataLength = (byte)(source[startIndex + 1] + 2);
            if (DataLength != 2 + 7)
            {
                //Logger.Warn($"位置附加信息的线路行驶时间不足/过长报警信息长度错误，略过解析");
                return null;
            }

            //路段ID
            LineSectionID = ParseHelper.Uint32(ref source, startIndex + 2);

            //路段行驶时间
            LineSectionDriveTime = ParseHelper.Uint16(ref source, startIndex + 6);

            //结果
            Result = source[startIndex + 8];

            return this;
        }
    }
}